﻿/*
Digraph (library for building, traversal, comparison and saving of directed
graph).

Copyright (C) 2014 Dmitry Merzagitovich Arslanov

This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option) any
later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*/

using System;

namespace Digraph
{
    internal sealed class Step<TVertex, TArc> :
        IEquatable<Step<TVertex, TArc>>
    {
        public Arc<TVertex, TArc> FromArc { get; private set; }

        public Arc<TVertex, TArc> ToArc { get; private set; }

        public Step(Arc<TVertex, TArc> fromArc,
                            Arc<TVertex, TArc> toArc)
        {
            FromArc = fromArc;
            ToArc = toArc;
        }

        public bool Equals(Step<TVertex, TArc> other)
        {
            if (other == null) return false;
            return FromArc == other.FromArc &&
                   ToArc == other.ToArc;
        }

        public override bool Equals(object obj)
        {
            return Equals(obj as Step<TVertex, TArc>);
        }

        public static bool operator ==(Step<TVertex, TArc> s1,
                                       Step<TVertex, TArc> s2)
        {
            return Equals(s1, s2);
        }

        public static bool operator !=(Step<TVertex, TArc> s1,
                                       Step<TVertex, TArc> s2)
        {
            return !Equals(s1, s2);
        }

        public override int GetHashCode()
        {
            int hashCode1 = FromArc.GetHashCode();
            int hashCode2 = ToArc.GetHashCode();
            return Tuple.Create(hashCode1, hashCode2).GetHashCode();
        }

        public override string ToString()
        {
            return string.Format("{0} {1}", FromArc, ToArc);
        }
    }
}
